package com.example.kafka.producer;

import com.alibaba.fastjson.JSONObject;
import com.example.kafka.vo.MessageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;

import java.util.Date;

@Service
public class Producer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    public void send(String i) {

        MessageVO messageVO = MessageVO.builder().id((System.currentTimeMillis())).msg("======" + i).sendTime(new Date()).build();
        ListenableFuture listenableFuture = kafkaTemplate.send("test", JSONObject.toJSONString(messageVO));
        System.out.println("Producer.send=====================");
    }

}